from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-09-15 14:10:41.858832
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 15, Sep, 2022
Time: 14:10:47
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.4222
Nobs: 780.000 HQIC: -50.7531
Log likelihood: 10003.4 FPE: 7.38637e-23
AIC: -50.9598 Det(Omega_mle): 6.58625e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298953 0.054118 5.524 0.000
L1.Burgenland 0.108781 0.036041 3.018 0.003
L1.Kärnten -0.106489 0.019163 -5.557 0.000
L1.Niederösterreich 0.207670 0.075389 2.755 0.006
L1.Oberösterreich 0.104683 0.072832 1.437 0.151
L1.Salzburg 0.252328 0.038490 6.556 0.000
L1.Steiermark 0.038263 0.050283 0.761 0.447
L1.Tirol 0.105882 0.040765 2.597 0.009
L1.Vorarlberg -0.059600 0.035078 -1.699 0.089
L1.Wien 0.053903 0.064866 0.831 0.406
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059118 0.112244 0.527 0.598
L1.Burgenland -0.035064 0.074750 -0.469 0.639
L1.Kärnten 0.047603 0.039746 1.198 0.231
L1.Niederösterreich -0.177065 0.156361 -1.132 0.257
L1.Oberösterreich 0.396450 0.151059 2.624 0.009
L1.Salzburg 0.288285 0.079830 3.611 0.000
L1.Steiermark 0.107162 0.104291 1.028 0.304
L1.Tirol 0.313299 0.084549 3.706 0.000
L1.Vorarlberg 0.027208 0.072753 0.374 0.708
L1.Wien -0.019960 0.134535 -0.148 0.882
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191131 0.027792 6.877 0.000
L1.Burgenland 0.089786 0.018509 4.851 0.000
L1.Kärnten -0.008394 0.009841 -0.853 0.394
L1.Niederösterreich 0.262922 0.038716 6.791 0.000
L1.Oberösterreich 0.129135 0.037403 3.453 0.001
L1.Salzburg 0.047041 0.019766 2.380 0.017
L1.Steiermark 0.018102 0.025823 0.701 0.483
L1.Tirol 0.093515 0.020935 4.467 0.000
L1.Vorarlberg 0.058998 0.018014 3.275 0.001
L1.Wien 0.118773 0.033312 3.565 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110378 0.028346 3.894 0.000
L1.Burgenland 0.045207 0.018877 2.395 0.017
L1.Kärnten -0.015327 0.010037 -1.527 0.127
L1.Niederösterreich 0.194760 0.039487 4.932 0.000
L1.Oberösterreich 0.288091 0.038148 7.552 0.000
L1.Salzburg 0.114448 0.020160 5.677 0.000
L1.Steiermark 0.101918 0.026337 3.870 0.000
L1.Tirol 0.113118 0.021352 5.298 0.000
L1.Vorarlberg 0.069645 0.018373 3.791 0.000
L1.Wien -0.022779 0.033975 -0.670 0.503
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.132686 0.051456 2.579 0.010
L1.Burgenland -0.052357 0.034268 -1.528 0.127
L1.Kärnten -0.039918 0.018221 -2.191 0.028
L1.Niederösterreich 0.171998 0.071681 2.399 0.016
L1.Oberösterreich 0.136333 0.069250 1.969 0.049
L1.Salzburg 0.287750 0.036597 7.863 0.000
L1.Steiermark 0.035390 0.047810 0.740 0.459
L1.Tirol 0.161519 0.038760 4.167 0.000
L1.Vorarlberg 0.100946 0.033352 3.027 0.002
L1.Wien 0.067694 0.061675 1.098 0.272
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058813 0.040924 1.437 0.151
L1.Burgenland 0.038845 0.027254 1.425 0.154
L1.Kärnten 0.051160 0.014491 3.530 0.000
L1.Niederösterreich 0.223182 0.057009 3.915 0.000
L1.Oberösterreich 0.283235 0.055076 5.143 0.000
L1.Salzburg 0.048999 0.029106 1.683 0.092
L1.Steiermark -0.004167 0.038024 -0.110 0.913
L1.Tirol 0.147589 0.030826 4.788 0.000
L1.Vorarlberg 0.072687 0.026526 2.740 0.006
L1.Wien 0.080594 0.049051 1.643 0.100
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180770 0.048899 3.697 0.000
L1.Burgenland -0.006660 0.032565 -0.205 0.838
L1.Kärnten -0.061161 0.017315 -3.532 0.000
L1.Niederösterreich -0.084114 0.068119 -1.235 0.217
L1.Oberösterreich 0.194159 0.065809 2.950 0.003
L1.Salzburg 0.056960 0.034778 1.638 0.101
L1.Steiermark 0.232258 0.045434 5.112 0.000
L1.Tirol 0.493174 0.036834 13.389 0.000
L1.Vorarlberg 0.048521 0.031695 1.531 0.126
L1.Wien -0.051692 0.058610 -0.882 0.378
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166667 0.056106 2.971 0.003
L1.Burgenland -0.009739 0.037364 -0.261 0.794
L1.Kärnten 0.067001 0.019867 3.372 0.001
L1.Niederösterreich 0.203313 0.078158 2.601 0.009
L1.Oberösterreich -0.071434 0.075508 -0.946 0.344
L1.Salzburg 0.212036 0.039903 5.314 0.000
L1.Steiermark 0.117288 0.052130 2.250 0.024
L1.Tirol 0.072713 0.042262 1.721 0.085
L1.Vorarlberg 0.122400 0.036366 3.366 0.001
L1.Wien 0.121441 0.067248 1.806 0.071
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357710 0.032509 11.003 0.000
L1.Burgenland 0.005996 0.021650 0.277 0.782
L1.Kärnten -0.023525 0.011511 -2.044 0.041
L1.Niederösterreich 0.217693 0.045286 4.807 0.000
L1.Oberösterreich 0.184652 0.043751 4.221 0.000
L1.Salzburg 0.045801 0.023121 1.981 0.048
L1.Steiermark -0.016442 0.030205 -0.544 0.586
L1.Tirol 0.107205 0.024488 4.378 0.000
L1.Vorarlberg 0.073895 0.021071 3.507 0.000
L1.Wien 0.048287 0.038965 1.239 0.215
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041137 0.150895 0.192117 0.156353 0.125261 0.113107 0.066484 0.223518
Kärnten 0.041137 1.000000 -0.002937 0.130934 0.041731 0.095746 0.430508 -0.052863 0.100929
Niederösterreich 0.150895 -0.002937 1.000000 0.337977 0.152541 0.300001 0.108022 0.183454 0.324204
Oberösterreich 0.192117 0.130934 0.337977 1.000000 0.228544 0.332405 0.172637 0.167759 0.267051
Salzburg 0.156353 0.041731 0.152541 0.228544 1.000000 0.147030 0.123870 0.147829 0.133705
Steiermark 0.125261 0.095746 0.300001 0.332405 0.147030 1.000000 0.152898 0.139177 0.079278
Tirol 0.113107 0.430508 0.108022 0.172637 0.123870 0.152898 1.000000 0.113732 0.153379
Vorarlberg 0.066484 -0.052863 0.183454 0.167759 0.147829 0.139177 0.113732 1.000000 0.006375
Wien 0.223518 0.100929 0.324204 0.267051 0.133705 0.079278 0.153379 0.006375 1.000000